<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">一体杆名称：</span>
      <el-input v-model="params.poleName" clearable placeholder="请输入一体杆名称" class="search-main" />
      <span class="search-label">一体杆编号：</span>

      <el-input v-model="params.poleNumber" clearable placeholder="请输入一体杆编号" class="search-main" />
      <span class="search-label">运行状态：</span>

      <el-select v-model="params.poleStatus">
        <!--
        下拉框选中的值：v-model绑定el-select
        下拉框展示的内容：：label（前端展示）--选项展示的值
        下拉框选择的值：  ：value（发送后台）--真正选中的值
        -->
        <el-option v-for="item in poleStatuslist" :key="item.id" :value="item.id" :label="item.name" />
      </el-select>

      <el-button type="primary" class="search-btn" @click="doSearch">查询</el-button>

    </div>

    <!-- 新增删除操作区域 -->
    <div class="create-container">
      <el-button type="primary" @click="poledialogVisible=true">添加一体杆</el-button>

      <el-button>批量删除</el-button>

    </div>

    <!-- 表格区域 -->
    <div class="table">
      <el-table
        ref="multipleTable"
        style="width: 100%"
        :data="poleList"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column type="index" label="序号" />
        <el-table-column label="一体杆名称" prop="poleName" />
        <el-table-column label="一体杆编号" prop="poleNumber" />
        <el-table-column label="一体杆IP" prop="poleIp" />
        <el-table-column label="安装区域" prop="areaName" />
        <el-table-column label="一体杆类型" prop="poleType">
          <template #default="{row}">
            <span>{{ row.poleType==='entrance'?"入口":row.poleType==='export'?"出口":'中心' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="运行状态" prop="poleStatus">
          <template #default="{row}">
            <span>{{ row.poleStatus===0?"正常":'异常' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="180">
          <!-- #default="scope" -->
          <template>
            <el-button size="mini" type="text">编辑</el-button>
            <el-button size="mini" type="text">删除</el-button>

          </template>

        </el-table-column>

      </el-table>

    </div>

    <div class="page-container">
      <!--
      公式：页数：总数/每页条数（默认10条）
      layout:分页器的布局样式，逗号隔开，
      total：标识展示总条数
      pager：页码
      next：下一页
      prev：上一页
      :page-size：表示每页的数据条数
      :total：表示数据总数
      @current-change：切换当前页码的事件
      -->
      <el-pagination
        layout="total,sizes, prev, pager, next"
        :page-size="params.pageSize"
        :total="total"
        :page-sizes="[2, 5, 10]"
        @current-change="pageChange"
        @size-change="handleSizeChange"
      />
    </div>
    <el-dialog
      title="添加一体杆"
      :visible.sync="poledialogVisible"
      width="580px"
    >
      <el-form>
        <el-form-item label="一体杆名称">
          <el-input placeholder="请输入一体杆名称" />
        </el-form-item>
        <el-form-item label="一体杆编号">
          <el-input placeholder="请输入一体杆编号" />
        </el-form-item>
        <el-form-item label="一体杆IP">
          <el-input placeholder="请输入一体杆IP" />
        </el-form-item>
        <el-form-item label="关联区域">
          <!-- <el-input placeholder="请选择关联区域" /> -->
          <el-select placeholder="请选择关联区域">
            <el-option />
          </el-select>
        </el-form-item>
        <el-form-item label="一体杆类型">
          <!-- <el-input placeholder="请选择一体杆类型" /> -->
          <el-select placeholder="请选择一体杆类型">
            <el-option />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { getPoleAPI } from '@/api/rodmanage'
export default {
  data() {
    return {
      params: {
        page: 1,
        pageSize: 5,
        poleName: '',
        poleNumber: '',
        poleStatus: ''
      },
      poledialogVisible: false,
      total: 0,
      poleList: [],
      poleStatuslist: [
        {
          id: null,
          name: '全部'
        },
        {
          id: 0,
          name: '正常'
        },
        {
          id: 1,
          name: '异常'
        }

      ]
    }
  },
  created() {
    this.getPole()
  },
  methods: {
    // 渲染列表
    async getPole() {
      const res = await getPoleAPI(this.params)
      console.log(res)
      this.poleList = res.data.rows
      this.total = res.data.total
    },
    // 查询列表
    doSearch() {
      this.params.page = 1
      this.getPole()
    },
    // 分页器
    pageChange(page) {
      this.params.page = page
      this.getPole()
    },
    handleSizeChange(val) {
      //  把点击的页数赋值给请求参数页数
      this.params.pageSize = val
      // 使用最新请求获取列表数据
      this.getPole()
    }
    // 新增数据

  }

}
</script>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;
  .search-main {
    width: 220px;
    margin-right: 10px;
  }
  .search-btn{
    margin-left:20px;
  }
}
.create-container{
  margin: 10px 0px;
}
.page-container{
  padding:4px 0px;
  text-align: right;
}
.form-container{
  padding:0px 80px;
}
</style>
